<template>
  <ul>
    <li v-for="item in formConfig.formItemList"
        :key="item.id">
      <!-- <baseInput :item="item"></baseInput> -->
      <linksTwo :item="item"></linksTwo>
      <!-- <component :is="item.baseType"></component> -->
    </li>
  </ul>
  <!-- <el-form class="dynamic-form"
           :inline="formConfig.inline"
           :model="value"
           :label-position="formConfig.labelPosition"
           :label-width="formConfig.labelWidth"
           :size='formConfig.size'
           :status-icon="formConfig.statusIcon">
    <dynamicFormItem v-for="item in formConfig.formItemList"
                     :key="item.key"
                     :item="item"
                     :value="value[item.key]"
                     @input="handleInput($event, item.key)"></dynamicFormItem>


  </el-form> -->
</template>

<script>
import dynamicFormItem from './dynamic-form-item'
import baseInput from '../baseForm/base/baseInput'
import linksTwo from '../baseForm/types/linksTwo'
export default {
  components: {
    dynamicFormItem,
    baseInput,
    linksTwo
  },
  props: {
    formConfig: {
      type: Object,
      required: true,
      default: () => { }
    },
    value: {
      type: Object,
      required: true
    }
  },
  watch: {
    formConfig: {
      handler (newName, oldName) {
        const formData = { ...this.value }
        this.formConfig.formItemList.forEach(({ key, value }) => {
          if (formData[key] === undefined || formData[key] === null) {
            formData[key] = value
          }
        })
        console.log(formData)
        // this.value = formData
      },
      deep: true
    }
  },
  methods: {
    setDefaultValue () {
      // 设置默认值
      // this.formConfig.formItemList.forEach(({ key, value }) => {
      //   // if (formData[key] === undefined || formData[key] === null) {
      //   //   formData[key] = value
      //   // }
      //   console.log(key, value)
      // })
      // this.$emit('input', formData)
    },
    handleInput (val, key) {
      this.value.key = val
      console.log(this.value)
    }
  },
  created () {
    this.setDefaultValue()
  },
}
</script>
